package com.foreknow.demo27;

public class TestTicketSell {
    public static void main(String[] args) {
        Ticket t = new Ticket();

        TicketThread t1 = new TicketThread("1号窗口",t);
        TicketThread t2 = new TicketThread("2号窗口",t);
        TicketThread t3 = new TicketThread("3号窗口",t);

        Thread tx1 = new Thread(t1);
        Thread tx2 = new Thread(t2);
        Thread tx3 = new Thread(t3);

        tx1.start();
        tx2.start();
        tx3.start();

        //数据是不同步的
        //原因：出现这种情况的主要原因就是第一个线程读取到100票号，没等卖的时间片结束，第二个线程抢到了时间片，读取票号100.
        //为了解决以上问题就需要建立同步(synchronized)方法或同步块

    }
}
